import java.util.Arrays;

public class Solution820 {

    static class Trie{

        Trie[] children=new Trie[26];

        void insert(String s){
            Trie node=this;
            for (char c : s.toCharArray()) {
                if (node.children[c-'a']==null){
                    node.children[c-'a']=new Trie();
                }
                node=node.children[c-'a'];
            }
        }

        boolean query(String s){
            Trie node=this;
            for (char c : s.toCharArray()) {
                if (node.children[c-'a']==null){
                    return false;
                }
                node=node.children[c-'a'];
            }
            return true;
        }
    }

    public int minimumLengthEncoding(String[] words) {
        Arrays.sort(words,(a,b)->b.length()-a.length());
        int ans=0;
        Trie trie=new Trie();
        for (String word : words) {
            String t=new StringBuilder(word).reverse().toString();
            if (!trie.query(t)){
                trie.insert(t);
                ans=ans+word.length()+1;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution820().minimumLengthEncoding(new String[]{"time", "me", "bell"}));
    }
}
